#include <iostream>
using namespace std;
void test()
{
    //[]捕获列表，捕获外部局部变量
    //()函数的参数列表
    // opt可选项，mutable(可修改)
    // returnType;函数的返回类型
    //{}函数的函数体
    /*[]()opt->returnType{
    }
    */
    int a = 520;
    [a](int value)
    {
        ++value;
        cout << "value = " << value << endl;
        cout << "a = " << a << endl;
    }(100);
    [&a](int value)
    {
        ++value;
        ++a;
        cout << "value = " << value << endl;
        cout << "a =" << a << endl;
    }(50);
}
int gCnt = 12345;
void test2()
{
    string name("WangDao");
    int age = 100;
    int num = 1;
    // 将外部的所有的局部变量进行值捕获
    [=](int value)
    {
        ++value;
        cout << "value = " << value << endl;
        cout << "age = " << age << endl;
        cout << "num = " << num << endl;
    }(100);
    // 将外部所有的局部变量进行引用捕获
    [&](int value)
    {
        ++age;
        ++num;
        cout << "value = " << value << endl;
        cout << "age = " << age << endl;
        cout << "num = " << num << endl;
    }(0);
    // name是引用捕获，其他局部变量进行值捕获
    [=, &name]
    {
        name = "hello";
        cout << "name = " << name << endl;
        cout << "age = " << age << endl;
        cout << "num = " << num << endl;
    }();
    [&,name]{
        //name是值捕获，其他都是值捕获
        ++age;
        ++num;
        cout << "age = " << age << endl;
        cout << "num = " << num << endl;
    }();
}
int main()
{
    test2();
    return 0;
}
